package com.xyxeshang.es.music.backend.controller;

import com.xyxeshang.es.music.backend.annotation.JwtCheck;
import com.xyxeshang.es.music.backend.entity.Playlist;
import com.xyxeshang.es.music.backend.service.PlaylistService;
import com.xyxeshang.es.music.backend.util.ResultUtil;
import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author xyx-Eshang
 */
@CrossOrigin
@RestController
@RequestMapping("/playlist")
public class PlaylistController {

	@Resource
	PlaylistService service;

	/**
	 * 创建歌单
	 *
	 * @param request
	 * @param playlistName
	 * @param playlistIntroduction
	 * @param playlistPictureUrl
	 * @param playlistLabelContentArr
	 * @return
	 */
	@JwtCheck
	@GetMapping("/createPlaylist")
	public ResultUtil<Integer> createPlaylist(HttpServletRequest request, String playlistName, String playlistIntroduction, String playlistPictureUrl, String[] playlistLabelContentArr) {
		return service.createPlaylist(request, playlistName, playlistIntroduction, playlistPictureUrl, playlistLabelContentArr);
	}

	/**
	 * 修改歌单
	 *
	 * @param playlistId
	 * @param playlistName
	 * @param playlistIntroduction
	 * @param playlistPictureUrl
	 * @param playlistLabelContentArr
	 * @return
	 */
	@JwtCheck
	@GetMapping("/updatePlaylist")
	public ResultUtil<Null> updatePlaylist(Integer playlistId, String playlistName, String playlistIntroduction, String playlistPictureUrl, String[] playlistLabelContentArr) {
		return service.updatePlaylist(playlistId, playlistName, playlistIntroduction, playlistPictureUrl, playlistLabelContentArr);
	}

	/**
	 * 新增歌曲到歌单中
	 *
	 * @param playlistId
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/addSong")
	public ResultUtil<Null> addSong(Integer playlistId, String songId) {
		return service.addSong(playlistId, songId);
	}

	/**
	 * 从歌单中移除歌曲
	 *
	 * @param playlistId
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/deleteSong")
	public ResultUtil<Null> deleteSong(Integer playlistId, String songId) {
		return service.deleteSong(playlistId, songId);
	}

	/**
	 * 点赞歌单
	 *
	 * @param request
	 * @param playlistId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/addLike")
	public ResultUtil<Null> addLike(HttpServletRequest request, Integer playlistId) {
		return service.addLike(request, playlistId);
	}

	/**
	 * 添加歌单评论
	 *
	 * @param request
	 * @param playlistCommentContent
	 * @param playlistId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/addComment")
	public ResultUtil<Integer> addComment(HttpServletRequest request, String playlistCommentContent, Integer playlistId) {
		return service.addComment(request, playlistCommentContent, playlistId);
	}

	/**
	 * 查询我的歌单
	 *
	 * @param request
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listMine")
	public ResultUtil<List<Playlist>> listMine(HttpServletRequest request) {
		return service.listMine(request);
	}

	/**
	 * 查询我点赞过的歌单
	 *
	 * @param request
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listMyLike")
	public ResultUtil<List<Playlist>> listMyLike(HttpServletRequest request) {
		return service.listMyLike(request);
	}

	/**
	 * 根据id获取
	 *
	 * @param playlistId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/getById")
	public ResultUtil<Playlist> getById(Integer playlistId) {
		return service.getById(playlistId);
	}
}
